
/**
 * bind css style with table rows of automatical alternation color change
 */

var basicRules = {
		/*
  '.grid TBODY TR' : function(element){
  	if(element.rowIndex != 0){
    	this.applyListTableStyle(element);
        Event.observe(element, 'mouseover',  this.mouseOverListTable.bindAsEventListener(this, element));
        Event.observe(element, 'mouseout',  this.mouseOutListTable.bindAsEventListener(this, element));
    }

  },*/

  '.grid thead TD' : function(element){
  	Event.observe(element, 'click',  this.clickListTable.bindAsEventListener(this, element));
  },

  /* apply the css style for list-table 
  applyListTableStyle: function (element) {
    if(element.childNodes.length > 1) {
         if(element.rowIndex % 2 == 0){
            element.className = 'even';
          }else {
            element.className = 'odd';
          }
      }
  },
  

  mouseOverListTable: function(event, element){
      element.className = 'over';
  },

  mouseOutListTable: function(event, element){
     this.applyListTableStyle(element);
  },*/
  
  clickListTable: function(event, element) {
  	var url = element.up(2).readAttribute('url');
	if(url) {
		var orderBy_ = element.readAttribute('orderBy_');
		if(orderBy_) {
			var sign = '?';
			if(url.indexOf('?') >= 0){
				sign = '&';
			}
			if(element.className == 'desc') {
			
				window.location.href = url +sign+ 'orderBy.' + orderBy_ + '=asc';	
			} else {
				window.location.href = url +sign+'orderBy.' + orderBy_ + '=desc';
			}			
		}
		
	} 
  }

};

Behaviour.register(basicRules);




